Demo notebook
Demo notebook¶
We can also create parts of our Jupyter Book based on Jupyter Notebooks.
Let’s simulate data for two conditions and print their first ten rows:
import numpy as np
cond_1 = np.random.rand(100)
print(f'Condition 1 = {cond_1[:10]}')
cond_2 = cond_1 + (np.random.rand(100))
print(f'Condition 2 = {cond_2[:10]}')
Condition 1 = [0.11107451 0.49710919 0.5566899 0.54504503 0.88877899 0.4875734
0.00502623 0.67200632 0.57936247 0.13563236]
Condition 2 = [0.5376877 0.93185037 1.007088 0.91623805 1.42370714 0.51151495
0.52945077 1.51943486 0.78810458 0.15808275]
We can also display in our Jupyter Book more complex datastructures, like pandas dataframes:
import pandas as pd
df = pd.DataFrame(
{'condition_1': cond_1, 'condition_2': cond_2},
index=np.arange(100)
)
df[:10]
| condition_1 | condition_2 | |
|---|---|---|
| 0 | 0.111075 | 0.537688 |
| 1 | 0.497109 | 0.931850 |
| 2 | 0.556690 | 1.007088 |
| 3 | 0.545045 | 0.916238 |
| 4 | 0.888779 | 1.423707 |
| 5 | 0.487573 | 0.511515 |
| 6 | 0.005026 | 0.529451 |
| 7 | 0.672006 | 1.519435 |
| 8 | 0.579362 | 0.788105 |
| 9 | 0.135632 | 0.158083 |
And of course, we can display plots as well!
import matplotlib.pyplot as plt
plt.scatter(cond_1, cond_2, alpha=.6)
plt.xlabel('condition 1')
plt.ylabel('condition 2')
plt.title('Scatterplot')
plt.show()
import ipywidgets as widgets
widgets.IntSlider()
from IPython.display import display
w = widgets.IntSlider()
display(w)
a = widgets.FloatText()
b = widgets.FloatSlider()
display(a,b)
mylink = widgets.jslink((a, 'value'), (b, 'value'))
#slider.close()
from ipywidgets import Layout, Button, Box
items_layout = Layout( width='auto') # override the default width of the button to 'auto' to let the button grow
box_layout = Layout(display='flex',
flex_flow='column',
align_items='stretch',
border='solid',
width='50%')
words = ['correct', 'horse', 'battery', 'staple']
items = [Button(description=word, layout=items_layout, button_style='danger') for word in words]
box = Box(children=items, layout=box_layout)
box
import ipywidgets as widgets
widgets.Password(
value='password',
placeholder='Enter password',
description='Password:',
disabled=False
)
import plotly.express as px
df = px.data.stocks(indexed=True)-1
fig = px.area(df, facet_col="company", facet_col_wrap=2)
fig.show()
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
import plotly.express as px
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
center=dict(lat=0, lon=180), zoom=0,
mapbox_style="stamen-terrain")
fig.show()